package framework.widgets;

import framework.types.TPoint.IntPoint;
import framework.types.TCoord.IntCoord;
import framework.types.TRect.IntRect;

/**
*  裁剪容器
**/
class CroppedContainer {

	private var _margin:IntRect;
	private var _coord:IntCoord;
	private var _absolutePosition:IntPoint;

	private var _isMargin:Bool;
	private var _croppedParent:CroppedContainer;

    public function new() {
		super();
    }


	public function getLeft():Int{
		return _coord.left;
	}

	public function getRight():Int{
		return _coord.right();
	}

	public function getTop():Int{
		return _coord.top;
	}

	public function getBottom():Int{
		return _coord.bottom();
	}

	public function getWidth():Int{
		return _coord.width;
	}

	public function getHeight():Int{
		return _coord.height;
	}

	public function getViewLeft():Int{
		return _coord.left + _margin.left;
	}

	public function getViewRight():Int{
		return _coord.right() - _margin.right;
	}

	public function getViewTop():Int{
		return _coord.top + _margin.top;
	}

	public function getViewBottom():Int{
		return _coord.bottom() - _margin.bottom;
	}

	public function getViewWidth():Int{
		return _coord.width - _margin.right - _margin.left;
	}

	public function getViewHeight():Int{
		return _coord.height - _margin.top - _margin.bottom;
	}

	public function getMargin():IntRect{
		return _margin;
	}

	public function getMarginLeft():Int{
		return _margin.left;
	}

	public function getMarginRight():Int{
		return _margin.right;
	}

	public function getMarginTop():Int{
		return _margin.top;
	}

	public function getMarginBottom():Int{
		return _margin.bottom;
	}

	public function setCroppedParent(parent:CroppedContainer):Void{
		this._croppedParent = parent;
	}

	/**
	*	是否被父节点裁剪
	**/
	public function isMargin():Bool{
		return _isMargin;
	}

	public function checkMargin():Bool{
		var margin = false;

		if(getLeft() < _croppedParent.getMarginLeft()){
			_margin.left = _croppedParent.getMarginLeft() - getLeft();
			margin = true;
		}else{
			_margin.left = 0;
		}

		if(getRight() > _croppedParent.getWidth() - _croppedParent.getMarginRight()){
			_margin.right = getRight() - (_croppedParent.getWidth() - _croppedParent.getMarginRight());
			margin = true;
		}else{
			_margin.right = 0;
		}

		if(getTop() < _croppedParent.getMarginTop()){
			_margin.top = _croppedParent.getMarginTop() - getTop();
			margin = true;
		}else{
			_margin.top = 0;
		}

		if(getBottom() > _croppedParent.getHeight() - _croppedParent.getMarginBottom()){
			_margin.bottom = getBottom() - (_croppedParent.getHeight() - _croppedParent.getMarginBottom());
			margin = true;
		}else{
			_margin.bottom = 0;
		}

		return margin;
	}


	public function checkOutside():Bool{
		return (
			(getRight() < _croppedParent.getMarginLeft()) ||
			(getLeft() > _croppedParent.getWidth() - _croppedParent.getMarginRight()) ||
			(getBottom() < _croppedParent.getMarginTop()) ||
			(getTop() > _croppedParent.getHeight() - _croppedParent.getMarginBottom())
		);
	}

}
